using System.Collections.Generic;

namespace ErkerTech.DeltaScope.Engine
{
    public class DeltaBlock
    {
        public DeltaBlock() : this(DeltaState.Invalid) { }
        public DeltaBlock(DeltaState state)
        {
            DiffState = state;
            Right = new List<string>();
            Left = new List<string>();
        }

        public bool IsCommitted { get; private set; }

        public IList<string> Left { get; private set; }
        public IList<string> Right { get; private set; }
        public DeltaState DiffState { get; private set; }

        public void Commit()
        {
            // Handle the setting of block state
            if (DiffState != DeltaState.Match)
            {
                if (Left.Count > 0 && Right.Count > 0)
                    DiffState = DeltaState.Changed;

                else if (Left.Count > 0)
                    DiffState = DeltaState.Deleted;

                else if (Right.Count  > 0)
                    DiffState = DeltaState.Inserted;

                else
                    DiffState = DeltaState.Invalid;
            }
            IsCommitted = true;
        }
    }
}